﻿package com.STS.ELearning.Captivate.properties 
{
	import com.STS.ELearning.Captivate.helpers.CaptivateHelper;
	
	public dynamic class BaseProperties implements ICaptivateWidgetData
	{
		
		private var _CpPropertiesObject:Object = null;
		
		
		public function BaseProperties()
		{
			
		}
		
		
		public function initializeFromString(xmlString:String):void {
			var xmlObject:Object = null;
			try {
				xmlObject = CaptivateHelper.createObjectFromXmlData(new XML(xmlString));
			}
			catch (err:Error){
				
				return;
			}
			initializeFromObject(xmlObject);
		}
		
		
		public function initializeFromObject(object:Object):void {
			if (_CpPropertiesObject != null) clearProperty();
			_CpPropertiesObject = object;
			for (var property:String in _CpPropertiesObject) {
				try {
					this[property] = _CpPropertiesObject[property];
				}
				catch (err:Error){
					trace("Couldn't find property: " + String(property));
				}
			}
		}

		
		private function clearProperty():void {
			for (var property:String in _CpPropertiesObject) {
				delete this[property];
			}
		}
		
		
	}
}